package tom_io_nio.bio;

import java.io.OutputStream;
import java.net.Socket;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;

public class BioClient {

    public static void main(String[] args){

        int count = 100;

        final CountDownLatch latch = new CountDownLatch(count);

        for(int i = 0;i < count; i++){
            new Thread(){
                @Override
                public void run() {
                    try {
                        latch.await();
                        Socket socket = new Socket("127.0.0.1",8080);
                        OutputStream os = socket.getOutputStream();
                        String name = UUID.randomUUID().toString();
                        os.write(name.getBytes());
                        os.close();
                        socket.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }.start();

            latch.countDown();
        }
    }
}
